from util.DataQuery.FormDataDecorator import FormDataDecorator
from util.selenium.webdriver.common.by import By

from base.BaseMethod import BM
from PageObject.WriteHrInfo import WriteHRInfo
from PageObject.WriteHrSubinfo import WriteHRSubinfo


class WriteHRForm():

    form_btn_loc = (By.LINK_TEXT, '人力资源情况表')
    content_iframe_loc = (By.CSS_SELECTOR, "#innocomFrame")
    title_loc = (By.CSS_SELECTOR, 'h2.text-center')

    upload_btn_loc = (By.CSS_SELECTOR, '.uploadAttachment a.btn')
    save_btn_loc = (By.CSS_SELECTOR, '.box-footer.text-right #dataEnmanressave')

    ent_doctor_loc = (By.CSS_SELECTOR, 'input#entHrDoctor')
    ent_master_loc = (By.CSS_SELECTOR, 'input#entHrMaster')
    ent_bachelor_loc = (By.CSS_SELECTOR, 'input#entHrBachelor')
    ent_junior_loc = (By.CSS_SELECTOR, 'input#entHrJunior')
    ent_senior_loc = (By.CSS_SELECTOR, 'input#entHrSenior')
    ent_middle_loc = (By.CSS_SELECTOR, 'input#entHrMiddle')
    ent_primary_loc = (By.CSS_SELECTOR, 'input#entHrPrimary')
    ent_mechanic_loc = (By.CSS_SELECTOR, 'input#entHrMechanic')
    ent_age1_loc = (By.CSS_SELECTOR, 'input#entHrAge1')
    ent_age2_loc = (By.CSS_SELECTOR, 'input#entHrAge2')
    ent_age3_loc = (By.CSS_SELECTOR, 'input#entHrAge3')
    ent_age4_loc = (By.CSS_SELECTOR, 'input#entHrAge4')

    # 写代码时方便提示, 基本方法完成后删除
    # driver = driver
    def __init__(self, driver=None):
        self.driver = driver

    @property
    def class_name(self):
        return self.__class__.__name__

    @FormDataDecorator
    def main(self, doctor=0, md=0, bd=0, coll=0, senior=0, medium=0, primary=0, snengr=0, age30al=0, age40al=0, age50al=0, age51au=0):
        BM.click(driver=self.driver, ele_loc=self.form_btn_loc)
        BM.cut_over_frame(driver=self.driver, selector_loc=self.content_iframe_loc)
        BM.wait(driver=self.driver, ele_loc=self.title_loc)
        BM.wait(driver=self.driver, ele_loc=self.save_btn_loc)
        # # # # # # # # # #  数据查询模块实现后需要先查询数据，在调用 write_hr_info 、 write_hr_subinfo 方法
        WriteHRInfo(driver=self.driver).write_hr_info()
        BM.input(ele_loc=self.ent_doctor_loc, driver=self.driver, keys=doctor)
        BM.input(ele_loc=self.ent_master_loc, driver=self.driver, keys=md)
        BM.input(ele_loc=self.ent_bachelor_loc, driver=self.driver, keys=bd)
        BM.input(ele_loc=self.ent_junior_loc, driver=self.driver, keys=coll)
        BM.input(ele_loc=self.ent_senior_loc, driver=self.driver, keys=senior)
        BM.input(ele_loc=self.ent_middle_loc, driver=self.driver, keys=medium)
        BM.input(ele_loc=self.ent_primary_loc, driver=self.driver, keys=primary)
        BM.input(ele_loc=self.ent_mechanic_loc, driver=self.driver, keys=snengr)
        BM.input(ele_loc=self.ent_age1_loc, driver=self.driver, keys=age30al)
        BM.input(ele_loc=self.ent_age2_loc, driver=self.driver, keys=age40al)
        BM.input(ele_loc=self.ent_age3_loc, driver=self.driver, keys=age50al)
        BM.input(ele_loc=self.ent_age4_loc, driver=self.driver, keys=age51au)

        # # # TODO 上传附件
        BM.click_upload(btn_loc=self.upload_btn_loc, driver=self.driver, class_name=self.class_name)
        BM.global_click_btn(btn_loc=self.save_btn_loc, driver=self.driver)

